/**
 * SpringMVC restful 风格
 * 共用控制器，控制关于共用的一些业务逻辑操作
 * @author yanwl
 * @date 2014-09-15
 */
package com.chnbst.bstyun.controller;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.chnbst.bstyun.core.common.BankpayConfig;
import com.chnbst.bstyun.core.common.DESUtil;
import com.chnbst.bstyun.core.common.HttpRequest;
import com.chnbst.bstyun.core.common.OaConfig;
import com.chnbst.bstyun.core.common.ReadProperties;
import com.chnbst.bstyun.core.common.SignUtil;
import com.chnbst.bstyun.core.common.email.EmailUtil;
import com.chnbst.bstyun.eos.Eos;
import com.chnbst.bstyun.eos.UserOperator;
import com.chnbst.bstyun.model.pojo.Email;
import com.chnbst.bstyun.model.pojo.Goods;
import com.chnbst.bstyun.model.pojo.GoodsRelation;
import com.chnbst.bstyun.model.pojo.Order;
import com.chnbst.bstyun.model.pojo.StaticData;
import com.chnbst.bstyun.model.pojo.User;
import com.chnbst.bstyun.model.pojo.extend.UserDelete;
import com.chnbst.bstyun.model.pojo.extend.UserPasswd;
import com.chnbst.bstyun.model.pojo.extend.UserRegister;
import com.chnbst.bstyun.model.pojo.extend.UserUpdate;
import com.chnbst.bstyun.model.pojo.temp.CallBill;
import com.chnbst.bstyun.model.vo.EmailVo;
import com.chnbst.bstyun.model.vo.OrderVo;
import com.chnbst.bstyun.service.EmailService;
import com.chnbst.bstyun.service.OrderService;
import com.chnbst.bstyun.service.StaticDataService;
import com.chnbst.bstyun.service.UserMessageService;
import com.chnbst.bstyun.service.UserService;

@Controller
@RequestMapping("/test")
public class TestController {
	/**
	 * 注入 业务逻辑层
	 */
	@Autowired
	private UserMessageService userMessageService;
	@Autowired
	private UserService userService;
	@Autowired
	private Eos eos;
	@Autowired
	private BankpayConfig bankpayConfig;
	@Resource 
	private TaskExecutor taskExecutor;//注入Spring封装的异步执行器
	@Autowired
	private OrderService orderService;
	@Autowired
	private UserOperator userOperator;
	@Autowired
	private StaticDataService staticDataService;
	@Autowired
	private OaConfig oa;
	@Autowired
	private EmailService emailService;
	@Autowired
	private ReadProperties read;

	@RequestMapping(value = "/testP", method = RequestMethod.GET)
	public void testP(HttpServletRequest request) throws Exception {
		//删除用户
		/*List<User> users = (List<User>)userService.TelExists("18958063782");
		User entity = users.get(0);
		
		UserDelete user = new UserDelete();
		user.setLoginName(new String[]{"18958063782"});
		System.out.println(userOperator.delete(user));
		
		eos.deleteIp(entity.getVirtualPhone());*/
//		eos.ktZZ("ywld101.com", "浙江百顺通信息科技有限公司", 5, SignUtil.str2Date("2015-06-01", "yyyy-MM-dd"),"","yunxt");
//		eos.updateOA("ywld30.com", "浙江百顺通信息科技有限公司", 8, SignUtil.str2Date("2015-06-01", "yyyy-MM-dd"));
		/*UserPasswd userPasswd = new UserPasswd();
		userPasswd.setLoginName("15958113322");
		userPasswd.setMd5(true);
		userPasswd.setPassword("00000000");
		System.out.println(userOperator.passwd(userPasswd));*/
		
		/*UserRegister uRegister = new UserRegister();
		uRegister.setLoginName("15867182427");
		uRegister.setDisplayName("ccdd");
		uRegister.setPassword("11111111");
		uRegister.setMd5(true);
		uRegister.setAllowMobileLogin(false);
		uRegister.setMobile("15867182427");
		uRegister.setEnable(true);
		String result = userOperator.register(uRegister);
		System.out.println(result);*/
		//正好达到到期时间
		/*Date overTime = SignUtil.getOvertime(5, +1, new Date());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userId", null);
		map.put("doType", 0);
		map.put("overTime", overTime);
		map.put("sortField", "pay_time");
		map.put("sortOrder", "desc");
		map.put("groupField", "t.user_id,t.goods_id");
		List<OrderVo> orders = orderService.selectLastOrdersByUserId(map);
		for (OrderVo order : orders) {
			System.out.println(order.getUserId()+"--"+order.getGoodsName()+"--"+order.getOrderNum()+"--"+order.getOverTime());
		}*/
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderState", 2);
		map.put("sortField", "o.pay_time");
		map.put("sortOrder", "desc");
		List<OrderVo> orders = orderService.selectCloseOrderVo(map);
		
		for (OrderVo order : orders) {
			System.out.println(order.getUserId()+"--"+order.getGoodsName()+"--"+order.getOrderNum()+"--"+order.getOverTime());
		}
	}
	
	@RequestMapping(value = "/testP1", method = RequestMethod.GET)
	public void testP1(HttpServletRequest request) throws Exception {
		eos.ktZZ("ywl4.com", "浙江百顺通信息科技有限公司", 500, SignUtil.str2Date("2015-05-01", "yyyy-MM-dd"),"","BST-CMS001");
	}
	
	@RequestMapping(value = "/testOA", method = RequestMethod.POST)
	@ResponseBody
	public void testOA(HttpServletRequest request) throws Exception {
		eos.ktZZ("ywl3.com", "浙江百顺通信息科技有限公司", 500, SignUtil.str2Date("2015-05-01", "yyyy-MM-dd"),"","BST-CMS001");
	}
	
	@RequestMapping(value = "/getMsg", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getMsg(HttpServletRequest request) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String[] str = eos.getOaMsg().split("\\|");
		String progress = str[1]+"%";
		String title = str[0];
		System.out.println(title+"---"+progress);
		map.put("progress", progress);
		map.put("title", title);
		return map;
	}
	
	@RequestMapping(value = "/toPage", method = RequestMethod.GET)
	public ModelAndView toPage(HttpServletRequest request) throws Exception {
		ModelAndView maView = new ModelAndView();
		maView.setViewName("test");
		return maView;
	}
	
	public static void main(String[] args) throws Exception {
		System.out.println(214);
	}
}
